package sword.T16;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: 18362
 * @Create: 2022-03-23 17:25:15 星期三
 */

class Solution {
    public double myPow(double x, int n) {
        if (x == 0.0)
            return 0;
        if (n == Integer.MIN_VALUE)
            return 1/x * myPow(x, n+1);
        if (n == 0)
            return 1;
        if (n < 0) {
            x = 1 / x;
            n = -n;
        }
        if (n == 1)
            return x;
        double t = myPow(x, n / 2);
        return n % 2 == 0 ? t*t : t*t*x;
    }
}